package com.ym.b2b.product.controller;

import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.ym.b2b.commons.controller.BaseController;
import com.ym.b2b.product.dao.EmBProductPictureDAO;
import com.ym.b2b.product.service.EmBProductPictureService;
import com.ym.b2b.product.sqlbean.EmBProductPicture;
import com.zc.commons.base.Result;

@Controller
@RequestMapping("/product")
public class ManagerProductPictureController extends BaseController {

    @Autowired
    private EmBProductPictureDAO     emBProductPictureDAO;

    @Autowired
    private EmBProductPictureService emBProductPictureService;

    @RequestMapping("searchEmBProductPicture.do")
    @ResponseBody
    public Result searchEmBProductPicture(EmBProductPicture emBProductPicture, HttpServletRequest req) {
        Result ret = new Result();
        try {
            List<EmBProductPicture> list = emBProductPictureDAO.searchEmBProductPicture(emBProductPicture);
            ret.setRows(list);
        } catch (Exception e) {
            logger.error(e.getMessage(), e);
            ret.setCodeResult(Result.CODE_100, "查询异常");
        }
        return ret;
    }

    @RequestMapping("insertBatchEmBProductPicture.do")
    @ResponseBody
    public Result insertBatchEmBProductPicture(EmBProductPicture list) {
        Result ret = new Result();
        try {
            ret = emBProductPictureService.insertEmBProductPictureBatch(list.getList());
        } catch (Exception e) {
            ret.setCodeResult(Result.CODE_100, e.getMessage());
        }
        return ret;
    }

    @RequestMapping("deleteBatchEmBProductPicture.do")
    @ResponseBody
    public Result deleteBatchEmBProductPicture(EmBProductPicture list) {
        Result ret = new Result();
        try {
            ret = emBProductPictureService.deleteBatchEmBProductPicture(list);
        } catch (Exception e) {
            ret.setCodeResult(Result.CODE_100, e.getMessage());
        }
        return ret;
    }

    @RequestMapping("updateEmBProductPictureDefault.do")
    @ResponseBody
    public Result updateEmBProductPictureDefault(EmBProductPicture empic) {
        Result ret = new Result();
        try {
            ret = emBProductPictureService.updateEmBProductPictureDefault(empic);

        } catch (Exception e) {
            logger.error(e.getMessage(), e);
            ret.setCodeResult(Result.CODE_100, e.getMessage());
        }
        return ret;
    }

    @RequestMapping("updateEmBProductPicture.do")
    @ResponseBody
    public Result updateEmBProductPicture(EmBProductPicture empic) {
        Result ret = new Result();
        try {
            emBProductPictureDAO.updateEmBProductPicture(empic);
        } catch (Exception e) {
            logger.error(e.getMessage(), e);
            ret.setCodeResult(Result.CODE_100, e.getMessage());
        }
        return ret;
    }
}
